<?php
	/* Extremely sorry for this mess. We display different links and a logout if the
		user is logged in as an admin. */
	date_default_timezone_set('America/New_York');
	require_once("globals.php");
	require_once("header_functions.php");
	session_start();
?>

<div id="welcomeMessage" style="float: left;">
</div>
<?php 
	if(adminIsLoggedIn()):
?>
	<div style="float:right;" id="logoutButton">
		<form action='/proj2/public_header.php' method='post'>
			<input type='submit' value='Logout' name='LogoutSubmit'>
		</form>
	</div>
	<div style="clear:both;"></div>
	<a href="/proj2/create_ticket.php">Submit New Ticket</a>	
	<a href="/proj2/admin_page.php">Admin Page</a>
<?php else: ?>
	<br />
	<a href="/proj2/admin_login.php">Admin Login</a>
	<a href="/proj2/create_ticket.php">Submit New Ticket</a>
<?php
	endif;
?>


<div id="linkBar">
	
</div>
<hr />
<?php
	/* Use this header for public pages that anyone should be able to access.
	Possibly like a page where tickets are submitted by anyone without
	logging in. */
	
	enforceLogInPolicy();
	// displayLogOutForAdmin();
	// displayDynamicLinkBar();
	if($_SERVER['REQUEST_METHOD'] == 'POST'):
		checkForLogOutSubmit();
	elseif($_SERVER['REQUEST_METHOD'] == 'GET'):
		
	endif;
	
	function enforceLogInPolicy()
	{
		if(adminIsLoggedIn()):
			$username = $_SESSION['admin_username'];
			$welcomeMessage = "Welcome, $username.<br/ >";
			setElementByID("welcomeMessage", $welcomeMessage);
		else:
			$welcomeMessage = "Welcome, anonymous.<br/>";
			setElementByID("welcomeMessage", $welcomeMessage);
		endif;
	}
	
	function checkForLogOutSubmit()
	{
		if(isset($_POST['LogoutSubmit'])):
			destroySession();
			forgetRememberMeCookie();
		else:
			return;
		endif;
	}
	
	function displayLogoutForAdmin()
	{
		if(adminIsLoggedIn()):
			setElementByID("logoutButton", "<form action='/proj2/public_header.php' method='post'>
					<input type='submit' value='Logout' name='LogoutSubmit'>
				</form>");
		else:
			
		endif;
	}
	
	function logoutForm()
	{
		
	}
	
?>

